//
//  NSString+Regex.m
//  PinYinProject
//
//  Created by bj_szd on 2025/2/15.
//

#import "NSString+Regex.h"

@implementation NSString (Regex)

-(BOOL)checkIsBlank {
    if ([self isKindOfClass:[NSString class]] &&
        ![self isEqualToString:@"<null>"] &&
        ![self isEqualToString:@"(null)"] &&
        ![self isEqualToString:@"<NULL>"] &&
        ![self isEqualToString:@"(NULL)"] &&
        ![self isEqualToString:@"null"] &&
        ![self isEqualToString:@"NULL"] &&
        self.length > 0) {
        return NO;
    } else {
        return YES;
    }
}

-(BOOL)checkIsEmail{
    NSString *regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    BOOL isValid = [predicate evaluateWithObject:self];
    if (isValid) {
        return YES;
    } else {
        return NO;
    }
}

-(BOOL)checkIsPunctuationMark {
    NSString *regex = @"[[:punct:]]";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    BOOL isValid = [predicate evaluateWithObject:self];
    if (isValid) {
        return YES;
    } else {
        return NO;
    }
}

-(BOOL)checkIsChinesePunctuationMark {
    NSString *regex = @"[\p{P}]";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    BOOL isValid = [predicate evaluateWithObject:self];
    if (isValid) {
        return YES;
    } else {
        return NO;
    }
}

-(BOOL)checkIsEnglishPunctuationMark {
    NSString *regex = @"[[:punct:]&&[@_'.#]]";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    BOOL isValid = [predicate evaluateWithObject:self];
    if (isValid) {
        return YES;
    } else {
        return NO;
    }
}

@end
